﻿using DevComponents.DotNetBar;
using ESRI.ArcGIS.Carto;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace PlanningGIS.File
{
    /// <summary>
    /// 
    /// </summary>
    public partial class FrmMaps : Office2007Form
    {
        /// <summary>
        /// 
        /// </summary>
        public FrmMaps()
        {
            InitializeComponent();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void FrmMaps_Load(object sender, EventArgs e)
        {
            
            
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="document"></param>
        public void AddMaps(IMapDocument document)
        {
            int mcnt = document.MapCount;
            for(int i = 0; i < mcnt; i++)
            {
                IMap m = document.Map[i];
                int idx =  dgrdvwMaps.Rows.Add(new string[] { i.ToString(), m.Name });
                dgrdvwMaps.Rows[idx].Tag = m;
                if (document.ActiveView.FocusMap.Name.Equals(m.Name, StringComparison.CurrentCultureIgnoreCase))
                {
                    dgrdvwMaps.Rows[idx].DefaultCellStyle.ForeColor = Color.Red;
                }
            }
            
        }

        /// <summary>
        /// 
        /// </summary>
        public IMap FocusMap { get; private set; }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnOK_Click(object sender, EventArgs e)
        {
            FocusMap = dgrdvwMaps.SelectedRows[0].Tag as IMap;
            this.DialogResult = DialogResult.OK;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void dgrdvwMaps_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            btnOK_Click(null, null);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
        }
    }
}
